package com.uzai.console.service.feign.dto;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.uzai.common.utils.DateUtil;
import com.uzai.console.dto.QueryParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author mingyang.chen create in 2022/10/28 15:37
 */
@ApiModel("淘宝订单修改参数")
@EqualsAndHashCode(callSuper = true)
@Data
public class HistoryTbOrderOptDto extends QueryParam {

    @ApiModelProperty("订单id")
    private Long id;
    @ApiModelProperty("订单编号")
    private String orderNo;
    @ApiModelProperty("父订单编号")
    private String parentOrderNo;
    @ApiModelProperty("用户ID")
    private Long userId;
    @ApiModelProperty("用户昵称")
    private String nickName;
    @ApiModelProperty("商品名称")
    private String title;
    @ApiModelProperty("商品ID")
    private String itemId;
    @ApiModelProperty("机器人ID")
    private Long deviceUniqueId;
    @ApiModelProperty("机器人ID列表")
    private List<Long> deviceUniqueIdList;
    @ApiModelProperty("商品类目")
    private Integer cid;
    @ApiModelProperty("订单状态(0订单付款 1订单结算 2订单失效 3维权中 4维权成功)")
    private Integer status;
    @ApiModelProperty("订单状态集合(0订单付款 1订单结算 2订单失效 3维权中 4维权成功)")
    private List<Integer> statusList;
    @ApiModelProperty("返利状态（0未返利 1已返利 2回收返利 3返利冻结）")
    private Integer reStatus;
    @ApiModelProperty("订单分类（淘宝、天猫、聚划算、饿了么、免单、淘宝特价版）")
    private Integer orderType;
    @ApiModelProperty("订单来源（0 PC个人微信，1 安卓手机个人微信,2 PC企业微信,3 Ipad协议个人微信,4 CMS, 5 小程序, 6 公众号")
    private Integer orderSource;
    @ApiModelProperty("联盟账号")
    private String alimmTbId;
    @ApiModelProperty("佣金比例(返利比例大于条件字段)")
    private Double commissionRate;
    @ApiModelProperty("买家返利(买家返利大于条件字段)")
    private Double reUserBal;
    @ApiModelProperty("查询时间类型(createdt-创建时间;paydt-付款时间;accountdt-结算时间;refundCreateTime-维权创建时间;refundFinishTime-维权完成时间")
    private String queryTimeType;
    @ApiModelProperty("查询开始时间")
    private Integer queryStartTime;
    @ApiModelProperty("查询结束时间")
    private Integer queryEndTime;
    @ApiModelProperty("查询月份(默认空表示查询最近三个月)")
    private String queryMonth;
    @ApiModelProperty(value = "查询月份第一天", hidden = true)
    private Integer queryMonthStartTime;
    @ApiModelProperty(value = "查询月份最后一天", hidden = true)
    private Integer queryMonthEndTime;
    @ApiModelProperty(value = "是否是饿了么订单（0否，1是）", hidden = true)
    private Integer elm;
    @ApiModelProperty("免单类型（0非免单，1免单）")
    private Integer free;
    @ApiModelProperty("维权创建时间")
    private Integer refundCreateTime;
    @ApiModelProperty("维权完成时间")
    private Integer refundFinishTime;


    public String getItemId() {
        if (StringUtils.isNotBlank(itemId)) {
            String[] itemIdArr = itemId.split("-");
            if (itemIdArr != null && itemIdArr.length == 2) {
                return itemIdArr[1];
            }
        }
        return itemId;
    }

    public Integer getQueryMonthEndTime() {
        //如果查询月份不为空，则结束时间为当月最后一天
        if (StringUtils.isNotBlank(queryMonth)) {
            queryMonthEndTime = DateUtil.getStartTimeOrEndTimeByMonth(queryMonth, 1);
        }
        return queryMonthEndTime;
    }

    public Integer getQueryMonthStartTime() {
        //如果查询月份不为空，则开始时间为当月得第一天
        if (StringUtils.isNotBlank(queryMonth)) {
            queryMonthStartTime = DateUtil.getStartTimeOrEndTimeByMonth(queryMonth, 0);
        } else {//默认为90天前
            //获取当前得月份
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String day = sdf.format(new Date());
            String currentTime = day + " 00:00:00";
            String queryStartTime = DateUtil.getSpecifiedDayBefore(currentTime, "yyyy-MM-dd HH:mm:ss", 90);
            queryMonthStartTime = DateUtil.getStrTime(queryStartTime);
        }
        return queryMonthStartTime;
    }


}
